home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1990 / number5 / silvtest.c < prev    next >
Text File  |  1990-09-25  |  2KB  |  59 lines

  1. #include <dos.h>
  2. #include <stdio.h>
  3. #include "swcasync.h"
  4. #include "swcxym.h"
  5. #include "swvideo.h"
  6.  
  7. #define TXQSIZE     (ULONG)2000
  8. #define RXQSIZE     TXQSIZE
  9. #define BAUDRATE    (ULONG)1200
  10.  
  11. void cleanup(void);
  12.  
  13. SWCCB *pPort;         /* functions, constants, prefixed by SW  */
  14. SWCFILETRANSCB *ftb;  /* are those provided by SilverWare Inc. */
  15.  
  16. main()
  17. {
  18. int ch, status;  /* variables for character read, returned status */
  19.  
  20.   pPort = pPort=SWCOpenComm(COM1,RXQSIZE,TXQSIZE,0,&status);
  21.   if(!pPort) {
  22.     printf
  23.     ("%s error from SWCOpenComm()\n",SWCErrorToText(status,0));
  24.     exit(1);
  25.   }
  26.   SWCSetUART(pPort,BAUDRATE,SWPARITYNONE,8,1);
  27.   atexit(cleanup);   /* cleanup routine executes at program end */
  28.  
  29.   while( 1 ) {       /* main program loop, repeat over and over */
  30.  
  31.     while (!SWCReceiveQueueEmpty(pPort))  /* if queue not empty */
  32.     putch(SWCReceiveCharacter(pPort) & 0xff); /* char to screen */
  33.  
  34.     if (kbhit()) {      /* keyboard handler, execute if key hit */
  35.       ch = getch();
  36.       if (ch) SWCTransmitCharacter(pPort,ch); /* if <>0, send it */
  37.       else switch (getch()) {  /* if 0, next char is a scan code */
  38.         case 0x51:    /* if scan code = PgDn, do XMODEM download */
  39.           ftb=SWCXYModemSetup(pPort,SWCXMODEM,SWCRECEIVE,
  40.                               0,&status,"file");
  41.           if(ftb) {
  42.                 SWCReceiveXMODEM(ftb);
  43.                 SWCFileTransferComplete(ftb);
  44.           }
  45.           else printf("%s error from SWCXYModemSetup()\n",
  46.                     SWCErrorToText(status,0));
  47.           break;
  48.         case 0x2d:                     /* if scan code is Alt-X */
  49.           exit(0);                     /* terminate the program */
  50.       }
  51.     }
  52.   }
  53. }
  54.  
  55. void cleanup(void)  /* cleanup executes when program terminates */
  56. {
  57.   SWCCloseComm(pPort,0); /* restore state of UART, int. vector */
  58. }
  59.